package com.yunxin.websitebox.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunxin.websitebox.entity.WebsiteUser;
import com.yunxin.websitebox.exception.UserBlockedException;
import com.yunxin.websitebox.exception.UserNotExistsException;
import com.yunxin.websitebox.mapper.WebsiteUserMapper;
import com.yunxin.websitebox.service.WebsiteUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: lcj
 * @Date: 2020/10/12 17:28
 * @Description: 用户管理业务接口实现类
 * @Version: 0.0.1
 */
@Service
public class WebsiteUserServiceImpl extends ServiceImpl<WebsiteUserMapper, WebsiteUser> implements WebsiteUserService {

    @Autowired
    private WebsiteUserMapper websiteUserMapper;

    /**
     * 用户登录
     * @param username
     * @return
     */
    @Override
    public WebsiteUser login(String username) {
        QueryWrapper<WebsiteUser> wrapper = new QueryWrapper<>();
        wrapper.eq("user_name", username);
        WebsiteUser user = websiteUserMapper.selectOne(wrapper);
        if (user == null) {
            throw new UserNotExistsException();
        }
        if (user.getStatus() == 20) {
            throw new UserBlockedException();
        }
        return user;
    }
}
